##### FOR FIGURE S15 IN THE SI: 

library(foreign)
library(ggplot2) 
library(gridExtra)
library(knitr)
library(grid)
library(dplyr)
library(forcats)
#install.packages("extrafont")
library(extrafont)
#install.packages("performance")
library("performance")
library("see")
library("haven")

rm(list=ls())
setwd("~/Dropbox/Side projects/BET HOUSES PROJECT/data/Gambling_Replication_Materials/Estimates")
setwd("~/Dropbox/EUI/BET HOUSES PROJECT/data/Gambling_Replication_Materials/Estimates")

all <- read_dta("diff_type_S15.dta")

all$id2 <- factor(all$inc,
                  levels = c(0,1),
                  labels = c("Only schools in neigh.\nbelow average income","All schools"))

theme_results <- theme_bw(base_size = 15) +
  theme(text=element_text(family="Times",
                          size = 15),
        axis.text.x = element_text(size = 15, color = "black"),
        axis.text.y = element_text(size = 15, color = "black"),
        axis.title.y = element_text(size = 15, color = "black"),
        axis.title.x = element_text(size = 15, color = "black"),
        legend.position = "top",
        legend.key.size = unit(1.2, "cm"),
        legend.text = element_text(size = 15),
        legend.title = element_text(size = 15),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        strip.text.y.right = element_text(angle = 0))

palette2 = c("black", "blue")

figureS15 <- all %>%
  ggplot(aes(x = id2, y = coef, colour = id2)) +   
  geom_point(size = 2 ,position = position_dodge(.5)) +
  geom_errorbar(aes(ymax = ci_upper95, ymin = ci_lower95), width = 0,  size = .7, position = position_dodge(width = .5)) +
  geom_errorbar(aes(ymax = ci_upper90, ymin = ci_lower90), width = 0, size = 1.6, position = position_dodge(width = .5)) +
  ylim(-1,1) +
  geom_hline(yintercept = 0, 
             linetype = 2, color = "black") + 
  scale_color_manual(name = "",values = palette2)+
  ylab("Difference in the effect of new betting houses\nopening at less than 500m. on educational performance") +
  ggtitle("Effect on public high-schools vs effect on charter high-schools") +
  xlab("") +
  theme_results + 
  coord_flip() +
  theme(strip.background =element_rect(fill="white"),
        axis.title.y = element_text(size = 15, color = "black"),
        legend.position = "none",
        plot.title = element_text(hjust= 0.5))
figureS15
